from rest_framework import serializers

from app.models import Product, ProductSpec, ProductDetailImage


class ProductSpecSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProductSpec
        fields = ['spec_id', 'name', 'description', 'unit', 'price_for_display', 'price', 'discount', 'stock',
                  'image_url',
                  'is_on_shell', 'deposit', 'deposit_desc']


class ProductListResponseSerializer(serializers.ModelSerializer):
    specs = ProductSpecSerializer(many=True)

    class Meta:
        model = Product
        fields = ['product_id', 'name', 'category_id', 'image_url', 'description', 'specs', 'price', 'unit']


class ProductDetailImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProductDetailImage
        fields = ['id', 'image_url', 'order', 'description']


class ProductDetailResponseSerializer(serializers.ModelSerializer):
    specs = ProductSpecSerializer(many=True)
    detail_images = ProductDetailImageSerializer(many=True)

    class Meta:
        model = Product
        fields = ['product_id', 'name', 'category_id', 'image_url',
                  'description', 'detail_images', 'specs']
